function Util(){
	this.baseUrl = 'http://lion.shihou.tv';
	//狮吼之星
	this.shihou_start_url = this.baseUrl + '/api/gift/receive_rank?gift_id=1051';
	this.shihou_start_data_array = [];
	this.shihou_start_data = {};
	//荣耀之星数据
	this.rongyao_start_url = this.baseUrl + '/api/gift/send_rank?gift_id=1051';
	this.rongyao_start_data_array = [];
	this.rongyao_start_data = {};
	//魅力之星
	this.meili_start_url = this.baseUrl + '/api/gift/receive_rank?gift_id=1052';
	this.meili_start_data_array = [];
	this.meili_start_data = {};
	//真爱之星
	this.love_start_url = this.baseUrl + '/api/user/watching_rank?gift_id=1052';
	this.love_start_data_array = [];
	this.love_start_data = {};
	//颜值之星(收到比♥的数量)
	this.face_start_url = this.baseUrl + '/api/gift/receive_rank?gift_id=1056';
	this.face_start_data_array = [];
	this.face_start_data = {};
	//狮吼星探
	this.xingtan_start_url = this.baseUrl + '/api/gift/send_rank?gift_id=1056';
	this.xingtan_start_data_array = [];
	this.xingtan_start_data = {};
	
	this.init();
}
Util.prototype={
	init: function(){
		
	},
	setRankList: function(page){
		var self = this;
		var roomSkip = '';
		var min = 0;
		var now = 0;
		//绑定榜单
		//狮吼之星
		self.log("狮吼之星")
		self.requestRemoteDataJson(self.shihou_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.shihou_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		min = now;
		//荣耀之星
		self.log("荣耀之星")
		self.requestRemoteDataJson(self.rongyao_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.rongyao_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		if(min > now){
			min = now;	
		}
		var phb1 = '';
		//排行榜赋值
		for(var i = 0;i < min+1;i++){
			var shihou = self.shihou_start_data_array[i];
			var rongyao = self.rongyao_start_data_array[i];
			if(page == 0){
				roomSkip = self.parseResult(shihou, 'user', 'room', 'jump');
			}else{
				roomSkip = 'http://event.m.shihou.tv/lion_module_share_temp/share?room_id='+self.parseResult(shihou, 'user', 'room', 'id');
			}
			phb1 += self.setRankListHTML((i+1), 1, roomSkip, self.parseResult(shihou, 'user', 'nick_name'), self.parseResult(shihou, 'user', 'avatar'), self.parseResult(shihou, 'user', 'room', 'vdo_status'), '收到'+self.parseResult(shihou, 'total')/10+'个');
			phb1 += self.setRankListHTML((i+1), 2, '', self.parseResult(rongyao, 'user', 'nick_name'), self.parseResult(rongyao, 'user', 'avatar'), self.parseResult(rongyao, 'user', 'room', 'vdo_status'), '送出'+self.parseResult(rongyao, 'total')/10+'个');
		}
		$('#phb1 ul').html(phb1);
		
		
		//颜值之星
		self.log("颜值之星")
		self.requestRemoteDataJson(self.face_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.face_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		min = now;
		//狮吼星探
		self.log("狮吼星探")
		self.requestRemoteDataJson(self.xingtan_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.xingtan_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		if(min > now){
			min = now;	
		}
		var phb3 = '';
		//排行榜赋值
		for(var i = 0;i < min+1;i++){
			var face = self.face_start_data_array[i];
			var xingtan = self.xingtan_start_data_array[i];
			if(page == 0){
				roomSkip = self.parseResult(face, 'user', 'room', 'jump');
			}else{
				roomSkip = 'http://event.m.shihou.tv/lion_module_share_temp/share?room_id='+self.parseResult(face, 'user', 'room', 'id');
			}
			phb3 += self.setRankListHTML((i+1), 1, roomSkip, self.parseResult(face, 'user', 'nick_name'), self.parseResult(face, 'user', 'avatar'), self.parseResult(face, 'user', 'room', 'vdo_status'), '收到'+self.parseResult(face, 'total')/10+'个');
			phb3 += self.setRankListHTML((i+1), 2, '', self.parseResult(xingtan, 'user', 'nick_name'), self.parseResult(xingtan, 'user', 'avatar'), self.parseResult(xingtan, 'user', 'room', 'vdo_status'), '送出'+self.parseResult(xingtan, 'total')/10+'个');
		}
		$('#phb3 ul').html(phb3);
		
		//魅力之星
		self.log("魅力之星");
		self.requestRemoteDataJson(self.meili_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.meili_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		min = now;
		//真爱之星
		self.log("真爱之星");
		self.requestRemoteDataJson(self.love_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'users');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.love_start_data_array[i] = user;
					now = i;
					if(i == 9){
						break;
					}
				}
			}
		}, false);
		if(min > now){
			min = now;	
		}
		
		var phb2 = '';
		//排行榜赋值
		for(var i = 0;i < min+1;i++){
			var meili = self.meili_start_data_array[i];
			var love = self.love_start_data_array[i];
			if(page == 0){
				roomSkip = self.parseResult(meili, 'user', 'room', 'jump');
			}else{
				roomSkip = 'http://event.m.shihou.tv/lion_module_share_temp/share?room_id='+self.parseResult(meili, 'user', 'room', 'id');
			}
			phb2 += self.setRankListHTML((i+1), 1, roomSkip, self.parseResult(meili, 'user', 'nick_name'), self.parseResult(meili, 'user', 'avatar'), self.parseResult(meili, 'user', 'room', 'vdo_status'), '收到'+self.parseResult(meili, 'total')/50+'个');
			phb2 += self.setRankListHTML((i+1), 2, '', self.parseResult(love, 'nick_name'), self.parseResult(love, 'avatar'), 0, minutesToHHmm(self.parseResult(love, 'desc')));
		}
		$('#phb2 ul').html(phb2);
		
		function minutesToHHmm(val){
			var hour =  parseInt(parseInt(val)/60);//小时
			var minu = parseInt(val) - hour*60;
			if(hour > 0){
				return hour+'小时'+minu+'分钟';
			}else{
				return minu+'分钟';
			}
		}
	},
	setRankListHTML: function(index, num, skipRoom, nick_name, avatar, kaibo_status, value){
		var html = '';
		var liClass = 'fcb';
		var clas = 'font2';
		var avatarHTML = '';
		var kaiboHTML = '';
		var rankIcon = '';
		
		if(index < 4){
			rankIcon = '<a class="icon"><img src="static/img/icon'+index+'.png" /> </a>';
		}else{
			liClass += ' hide';
			rankIcon = '<a class="icon paim4">'+index+'</a>';
		}
		
		if(kaibo_status == 1){//如果开播
			kaiboHTML = '     	<em></em>'+
						'<span></span>'+
                        '    <div class="loader-inner line-scale-pulse-out">'+
                        '        <div></div>'+
                        '        <div></div>'+
                        '        <div></div>'+
                        '        <div></div>'+
                        '        <div></div>'+
                        '    </div>';
		}
		if(num == 1){//第1排
			clas = 'font1';
			avatarHTML = '<div class="'+clas+'">'+ 
						'    <span>'+
		               '         <p class="fjh"><a>'+nick_name+'</a></p>'+
		               '         <p class="fjh number"><a>'+value+'</a></p>'+
		               '     </span>'+
		               '     <a href="'+skipRoom+'" class="iconImg no'+((index > 4)?4:index)+'">'+
		               '     	<div class="phbWrap">'+
		               				kaiboHTML+
		               '         	 <img src="'+avatar+'"/>'+
		               '         </div>'+
		               '     </a>';
		               '</div>';
		}else{//第2排
			avatarHTML = '<div class="'+clas+'">'+
					'     <a  class="iconImg no'+((index > 4)?4:index)+'">'+
						'     	<div class="phbWrap">'+
									kaiboHTML+
						'         	  <img src="'+avatar+'"/>'+
						'         </div>'+
						'     </a>'+
						'    <span>'+
		               '         <p class="fjh"><a>'+nick_name+'</a></p>'+
		               '         <p class="fjh number"><a>'+value+'</a></p>'+
		               '     </span>'+
		               rankIcon+
		               '</div>';
		}
		html = '<li class="'+liClass+'">'+
	               avatarHTML+
	            '</li>';
		return html;
	},
	setUserRank: function(user_id){
		var self = this;
		//绑定用户排名
		//狮吼之星
		self.requestRemoteDataJson(self.shihou_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.shihou_start_data['"'+self.parseResult(user, 'user', 'id')+'"'] = (i+1);
				}
				$('#loginRank1 a').eq(0).html('魅力之星排名：'+setUR(self.shihou_start_data, user_id));		
			}
		}, true);
		//荣耀之星
		self.requestRemoteDataJson(self.rongyao_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.rongyao_start_data['"'+self.parseResult(user, 'user', 'id')+'"'] = (i+1);
				}
				$('#loginRank1 a').eq(1).html('荣耀之星排名：'+setUR(self.rongyao_start_data, user_id));		
			}
		}, true);
		
		
		//颜值之星
		self.requestRemoteDataJson(self.face_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.face_start_data['"'+self.parseResult(user, 'user', 'id')+'"'] = (i+1);
				}
				$('#loginRank3 a').eq(0).html('颜值之星排名：'+setUR(self.face_start_data, user_id));		
			}
		}, true);
		//狮吼星探
		self.requestRemoteDataJson(self.xingtan_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.xingtan_start_data['"'+self.parseResult(user, 'user', 'id')+'"'] = (i+1);
				}
				$('#loginRank3 a').eq(1).html('狮吼星探排名：'+setUR(self.xingtan_start_data, user_id));		
			}
		}, true);
		
		//魅力之星	
		self.requestRemoteDataJson(self.meili_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'list');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.meili_start_data['"'+self.parseResult(user, 'user', 'id')+'"'] = (i+1);
				}
				$('#loginRank2 a').eq(0).html('人气之星排名：'+setUR(self.meili_start_data, user_id));
			}
		}, true);
		//真爱之星
		self.requestRemoteDataJson(self.love_start_url, {}, function(result){
			if(self.parseResult(result, 'error') == 0){
				var resultData = self.parseResult(result, 'data', 'users');
				for (var i = 0;i < resultData.length; i++) {
					var user = resultData[i];
					self.love_start_data['"'+self.parseResult(user, 'id')+'"'] = (i+1);
				}
				$('#loginRank2 a').eq(1).html('真爱之星排名：'+setUR(self.love_start_data, user_id));
			}
		}, true);
		function setUR(obj, user_id){
			var resu = obj['"'+user_id+'"'];
			if(resu == undefined){
				return '无'
			}
			return resu;
		}
	},
	//获取url中的参数
    getUrlParam: function(name, url) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        url = url || window.location.search.substr(1).match(reg);  //匹配目标参数
        if (url != null) return unescape(url[2]); return null; //返回参数值
    },
    getUrlParams: function(){
    	var url = window.location.href;  //匹配目标参数
    	if(url != null)
    		return url.substr(url.indexOf("?"), url.length);
    },
    parseResult:function(){//解析结果， 如果不存在则返回''
		var size = arguments.length;
		if(size == 0){
			return '';
		}
		var result = arguments[0];
		for(var i = 1; i < size; i++){
			if(result == undefined){
				return '';
			}
			var argu = arguments[i];
			if(i == size){
				return argu;
			}
			result = result[argu];
		}
		return result;
	},
	requestRemoteDataJson: function(url, data, callback, asyn){
		this.logURL(url);
		//this.logParameter(data);
		var begin = (new Date()).getTime();
		$.ajax({
	        url: url,
	        type: 'GET',
	        async: asyn,
	        cache: false, 
	        dataType: "json",
	        data: data,
	        success: callback,
	        error: function (data) {
	        	var status = data.status;
	        	console.log(url + "获取数据失败!");
	        }
	    });
	},
	log:function(data){
		console.log(data);
	},
	logURL:function(url){
		console.log("url --> "+url);
	},
	logParameter:function(data){
		console.log("parameter --> "+JSON.stringify(data));
	},
	logResult:function(result){
		console.log("result --> "+JSON.stringify(result));
	}
}
